import 'package:desktop_window/desktop_window.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class ScreenController extends GetxController {
  var count = 0.obs;

  var screenLeds = <Widget>[].obs;

  @override
  Future<void> onInit() async {
    super.onInit();
    for (int i = 0; i < 160; i++) {
      screenLeds.add(Container(
        color: Colors.black,
      ));
    }
    DesktopWindow.setWindowSize(const Size(655, 437));
  }

  setLeds(String value) {
    var leds = value.split(',');
    var tempLeds = List.filled(160, Container());
    for (int i = 0; i < 160; i++) {
      int line = i ~/ 16;
      if (line % 2 == 0) {
        tempLeds[i] = Container(
          color: Color.fromARGB(
            255,
            int.parse(leds[i].substring(3, 6)),
            int.parse(leds[i].substring(0, 3)),
            int.parse(leds[i].substring(6, 9)),
          ),
        );
      } else {
        tempLeds[16 * (line + 1) - i % 16 - 1] = Container(
          color: Color.fromARGB(
            255,
            int.parse(leds[i].substring(3, 6)),
            int.parse(leds[i].substring(0, 3)),
            int.parse(leds[i].substring(6, 9)),
          ),
        );
      }
    }
    screenLeds.value = tempLeds;
  }

  add() async {}
}
